package com.gome.util;

import etm.core.configuration.BasicEtmConfigurator;
import etm.core.configuration.EtmManager;
import etm.core.monitor.EtmMonitor;
import etm.core.monitor.EtmPoint;
import etm.core.renderer.SimpleTextRenderer;
import etm.core.timer.DefaultTimer;

/** 
 * 执行j从零至一百的循环递加，且当j为是的整数倍时调用方法LessJ(int j)LessJ(int j)--- 执行i 
 * >0的递减,使用JETM目的执行程序得到两个函数调用的次数及时间 
 * @author rwq 
 */  
public class JETMTest {  
	
	
    private static EtmMonitor monitor;  
  
    private static void setup() {  
        BasicEtmConfigurator.configure();  
        //BasicEtmConfigurator.configure(true);  
        //BasicEtmConfigurator.configure(true,new DefaultTimer());  
        monitor = EtmManager.getEtmMonitor();  
        monitor.start();  
    }  
  
    private static void tearDown() {  
        monitor.stop();  
    }  
  
    public static void main(String[] args) {  
        setup();  
        EtmPoint point = monitor.createPoint("00_JETMTest_main");  
        AddNumber add = new AddNumber();  
        add.addHun();  
        add.lessJ(10);  
        point.collect();  
        monitor.render(new SimpleTextRenderer());  
        tearDown();  
    }  
  
}  
  
class AddNumber {  
    private static final EtmMonitor etmMonitor = EtmManager.getEtmMonitor();  
    void addHun() {  
        // 数字序号_阶段名称_功能  
        EtmPoint point = etmMonitor.createPoint("01_AddNumber_addHun");  
        try {  
            int j = 0;  
            for (int i = 0; i < 100; i++) {  
                lessJ(j);  
            }  
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            point.collect();  
        }  
    }  
  
    void lessJ(int j) {  
        EtmPoint point = etmMonitor.createPoint("02_AddNumber_lessJ");  
        try {  
            int i = j;  
            for (; i > 0;) {  
                i--;  
            }  
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            point.collect();  
        }  
    }  
}  